package asteroids.expressions;

import java.util.*;

import asteroids.*;
import asteroids.types.*;

public class NotEqualExpression extends ComparisonExpression {

	public NotEqualExpression(int line, int column, Expression e1, Expression e2) {
		super(line, column, e1, e2);
	}

	@Override
	public Type evaluate(Ship ship, Map<String, Type> globals) {
		if(ship != null)
			return new BooleanType((getFirstExpression().evaluate(ship, globals)).getValue() != ( getSecondExpression().evaluate(ship, globals)).getValue());
		else
			return new BooleanType();
	}

	@Override
	public List<String> getTypeCheckErrorsExpressions(List<String> typeErrors, Map<String, Type> globals) {
		if(getFirstExpression().evaluate(null, globals).getClass() != getSecondExpression().evaluate(null, globals).getClass()) 
			typeErrors.add("Line: " + getLine() + " Column: " + getColumn() + " - The left operand, " + getFirstExpression().toString() + " is not of the same type as the right operand, " + getSecondExpression().toString() + ".");
		typeErrors = getFirstExpression().getTypeCheckErrorsExpressions(typeErrors, globals);
		typeErrors = getSecondExpression().getTypeCheckErrorsExpressions(typeErrors, globals);
		return typeErrors;
	}
	
	@Override
	public String toString() {
		return getFirstExpression().toString() + " != " + getSecondExpression().toString();
	}

}
